// Mock Data Index File
// This file imports and exports all mock data collections for easy access

// Import all mock data files
import { patients, patientVisits, appointments, followUps } from './patientData';
import { laboratoryResults, imagingResults, physicalExams } from './examData';
import { treatmentPlans, prescriptions } from './treatmentData';
import { departments, doctors, clinicRooms, schedules } from './organizationData';
import { 
  medicalPackages, 
  physicalExamPackages, 
  surgicalServices, 
  rehabilitationServices,
  healthEducation, 
  vaccinationServices 
} from './medicalServiceData';

// Export all mock data
export {
  // Patient related data
  patients,
  patientVisits,
  appointments,
  followUps,
  
  // Medical examination data
  laboratoryResults,
  imagingResults,
  physicalExams,
  
  // Treatment and prescription data
  treatmentPlans,
  prescriptions,
  
  // Organization data
  departments,
  doctors,
  clinicRooms,
  schedules,
  
  // Medical Service data
  medicalPackages,
  physicalExamPackages,
  surgicalServices,
  rehabilitationServices,
  healthEducation,
  vaccinationServices
};

/**
 * 使用说明:
 * 
 * 1. 在需要使用模拟数据的组件中导入所需的数据集合:
 *    import { patients, appointments } from '@/mock';
 * 
 * 2. 在实际开发中，可以基于这些模拟数据创建API模拟响应:
 *    例如使用 Mock.js 创建模拟API:
 *    
 *    // 在API模拟文件中
 *    import Mock from 'mockjs';
 *    import { patients } from '@/mock';
 *    
 *    Mock.mock('/api/patients', 'get', () => {
 *      return {
 *        code: 200,
 *        message: 'success',
 *        data: patients
 *      };
 *    });
 * 
 * 3. 在后端API已开发完成后，可以方便地切换到真实API:
 *    只需要修改API请求地址，不需要修改组件中的数据处理逻辑。
 */

// 提供一些常用的模拟数据获取方法
const mockApi = {
  // 获取患者详情
  getPatientById: (id) => {
    return patients.find(patient => patient.id === id) || null;
  },
  
  // 获取患者就诊记录
  getPatientVisits: (patientId) => {
    return patientVisits.filter(visit => visit.patientId === patientId);
  },
  
  // 获取患者预约记录
  getPatientAppointments: (patientId) => {
    return appointments.filter(appointment => appointment.patientId === patientId);
  },
  
  // 获取患者随访记录
  getPatientFollowUps: (patientId) => {
    return followUps.filter(followUp => followUp.patientId === patientId);
  },
  
  // 获取患者检验结果
  getPatientLabResults: (patientId) => {
    return laboratoryResults.filter(result => result.patientId === patientId);
  },
  
  // 获取患者影像结果
  getPatientImagingResults: (patientId) => {
    return imagingResults.filter(result => result.patientId === patientId);
  },
  
  // 获取患者处方
  getPatientPrescriptions: (patientId) => {
    return prescriptions.filter(prescription => prescription.patientId === patientId);
  },
  
  // 获取医生详情
  getDoctorById: (id) => {
    return doctors.find(doctor => doctor.id === id) || null;
  },
  
  // 获取科室详情
  getDepartmentById: (id) => {
    return departments.find(dept => dept.id === id) || 
           departments.flatMap(dept => dept.children || []).find(child => child.id === id) || 
           null;
  },
  
  // 获取医生排班
  getDoctorSchedule: (doctorName) => {
    return schedules.flatMap(schedule => 
      schedule.scheduleItems
        .filter(item => item.doctor === doctorName)
        .map(item => ({
          date: schedule.date,
          day: schedule.day,
          timeSlot: item.timeSlot,
          department: item.department,
          room: item.room,
          quota: item.quota,
          booked: item.booked,
          available: item.available
        }))
    );
  },
  
  // 根据日期获取排班
  getScheduleByDate: (date) => {
    return schedules.find(schedule => schedule.date === date) || null;
  },
  
  // 搜索患者
  searchPatients: (keyword) => {
    if (!keyword) return patients;
    
    const lowercaseKeyword = keyword.toLowerCase();
    return patients.filter(patient => 
      patient.name.toLowerCase().includes(lowercaseKeyword) ||
      patient.id.toLowerCase().includes(lowercaseKeyword) ||
      patient.phone.includes(keyword) ||
      patient.idCard.includes(keyword) ||
      (patient.tags && patient.tags.some(tag => tag.toLowerCase().includes(lowercaseKeyword)))
    );
  },
  
  // 搜索医生
  searchDoctors: (keyword) => {
    if (!keyword) return doctors;
    
    const lowercaseKeyword = keyword.toLowerCase();
    return doctors.filter(doctor => 
      doctor.name.toLowerCase().includes(lowercaseKeyword) ||
      doctor.department.toLowerCase().includes(lowercaseKeyword) ||
      doctor.specialty.toLowerCase().includes(lowercaseKeyword)
    );
  },
  
  // 获取医疗服务包
  getMedicalPackageById: (id) => {
    return medicalPackages.find(pkg => pkg.id === id) || null;
  },
  
  // 获取物理检查服务包
  getPhysicalExamPackageById: (id) => {
    return physicalExamPackages.find(pkg => pkg.id === id) || null;
  },
  
  // 获取外科服务
  getSurgicalServiceById: (id) => {
    return surgicalServices.find(service => service.id === id) || null;
  },
  
  // 获取康复服务
  getRehabilitationServiceById: (id) => {
    return rehabilitationServices.find(service => service.id === id) || null;
  }
};

export default mockApi; 